import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'

Vue.use(Vuex)

const state = () => {}

const actions = {}
const mutations = {}
const modulesFiles = require.context(`./modules`, true, /\.js$/)
const modules = modulesFiles.keys().reduce((module, modulePath) => {
  const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, `$1`)
  const $module = { ...module }
  const value = modulesFiles(modulePath)
  $module[moduleName] = value.default
  return $module
}, {})

export default new Vuex.Store({
  state,
  getters,
  mutations,
  actions,
  modules,
})
